package com.centling.smartSealForPhone.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.centling.smartSealForPhone.R;
import com.centling.smartSealForPhone.bean.AlarmListBean;

import java.util.List;

/**
 *
 * @author Sun
 * @date 2017/6/28
 */

public class RvAlarmListAdapter extends RecyclerView.Adapter<RvAlarmListAdapter.AlarmListViewHolder>{

    private Context context;
    private List<AlarmListBean.RowsEntity> list;
    private RvStampListAdapter.OnItemClickListener onItemClickListener;

    public RvAlarmListAdapter(Context context, List<AlarmListBean.RowsEntity> list){
        this.context = context;
        this.list = list;
    }

    @Override
    public AlarmListViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new AlarmListViewHolder(LayoutInflater.from(context).inflate(R.layout.rv_alarm_list_item, parent, false));
    }

    @Override
    public void onBindViewHolder(final AlarmListViewHolder holder, final int position) {
        holder.tvSealName.setText(list.get(position).getSealName());
        holder.tvOperaterName.setText(list.get(position).getOperatorName());
        holder.tvStartTime.setText(list.get(position).getAlarmTimeStartStr());
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if (onItemClickListener != null) {
                    onItemClickListener.onItemClick(holder.itemView, position);
                }
            }
        });
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    public void setOnItemClickListener(RvStampListAdapter.OnItemClickListener onItemClickListener) {
        this.onItemClickListener = onItemClickListener;
    }

    class AlarmListViewHolder extends RecyclerView.ViewHolder{
        TextView tvSealName, tvOperaterName, tvStartTime;
        AlarmListViewHolder(View itemView) {
            super(itemView);
            tvSealName= itemView.findViewById(R.id.tv_alarm_list_seal_name);
            tvOperaterName= itemView.findViewById(R.id.tv_alarm_list_operater_name);
            tvStartTime= itemView.findViewById(R.id.tv_alarm_list_start_time);
        }
    }
}
